package com.yellowpage.wf.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;
import com.yellowpage.wf.dao.ParticipantsDao;
import com.yellowpage.wf.data.Participants;

public class ParticipantsServiceImpl extends BaseServiceImpl implements ParticipantsService {
	  private ParticipantsDao participantsDao;
	
	  public void setParticipantsDao(ParticipantsDao participantsDao) {
		  this.participantsDao = participantsDao;
	  }
	
	
	  /* White generate Method */ 
	  public Participants getParticipants(Long id){
	      return participantsDao.get(id);
	  }
	  
    public List<Participants> getAllParticipants(){
        return participantsDao.getAll();
    }
    
    public List<Map> queryParticipantsByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.PARTICIPANTS_ID , a.PARTICIPANT_TYPE , a.PARTICIPANT_VALUE , a.WORKFLOW_NODE_ID , a.PARTICIPANT_NAME    FROM WF_PARTICIPANTS a WHERE 1=1 ")
				    			.addCondition(" and PARTICIPANTS_ID = :participantsId ")
							    			.addCondition(" and PARTICIPANT_TYPE = :participantType ")
							    			.addCondition(" and PARTICIPANT_VALUE = :participantValue ")
							    			.addCondition(" and WORKFLOW_NODE_ID = :workflowNodeId ")
							    			.addCondition(" and PARTICIPANT_NAME = :participantName ")
							    ; 	

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    

	public List<Map> getParticipantsByNode(Long workflowNodeId) {
		Map queryMap = new HashMap();
		queryMap.put("workflowNodeId", workflowNodeId.toString());
		QueryAssistantSQL sqlAssistant = baseDao
				.newQueryAssistantSQL(
						"SELECT a.PARTICIPANTS_ID , a.PARTICIPANT_TYPE , a.PARTICIPANT_VALUE , a.WORKFLOW_NODE_ID , a.PARTICIPANT_NAME FROM WF_PARTICIPANTS a WHERE 1=1 ")
				.addCondition(" and a.WORKFLOW_NODE_ID = :workflowNodeId ");

		List<Map> resultList = sqlAssistant.query(baseDao.getConnection(),
				queryMap);

		return resultList;
	}
    
    
    public void saveParticipants(Participants participants){
        participantsDao.save(participants);
    }
    
	  public void updateParticipants(Participants participants){
	      participantsDao.update(participants);
	  }
	  
	  public void delete(List deleteList){
	      participantsDao.remove(deleteList);
	  }
	  
	  
	 
	
}	